<?php
header("content-type: text/html; charset=utf-8");
require "../config/config.php";
require "../config/attributes.php";
require GALAXYTOOL_ROOT."/secret/includes/authorization.inc.php";
session_start();
require GALAXYTOOL_ROOT."/secret/includes/logincheck.inc.php";
require GALAXYTOOL_ROOT."/secret/includes/layout.inc.php";
require_once GALAXYTOOL_ROOT."/secret/includes/general.inc.php"; // loaded from plugins

$messages = null;
Galaxytool::load_language_file($_SESSION['lang']);

if ($_SESSION['s_auth']->get_permission(iAuthorization::permission_probeview) !== true) {
	$error_page_code = "permission";
	include GALAXYTOOL_ROOT."/secret/errorpage.php";
	exit();
}
try {
	$probe_helper        = new ProbeLanguages();
	$top_array           = $probe_helper->get_flipped_top_array();
} catch (Exception $e) {
	exit("Exception occurred: ".$e);
}

echo Layout::make_header(REPORTS_TITLE);

?>
<script type="text/javascript">
<?php
$resource_keys = array("metal","crystal","deuterium","energy");
$fleet_keys = array("kt","gt","lj","sj","krz","ss","kolo","rec","spio","bomb","zerri","ds","skrz","sat");
$defense_keys = array("rak","ll","sl","ion","gauss","plasma","ksk","gsk","arak","irak");
$building_keys = array("memi","krimi","deutsyn","solar","fusion","robo","nani","rawe","mesp","krissp","deutsp","folab","terra","allydep","raksilo","mbase","sensor","sprungtor");
$research_keys = array("spiolvl","computech","waffentech","schildtech","rpz","energytech","hypertech","vbt","impulse","hra","lasertech","iontech","plasmatech","forschungsnetz","expedition","gravi");
$all_db_keys = array($resource_keys, $fleet_keys, $defense_keys, $building_keys, $research_keys);
echo '
var resources_on_text = '.json_encode($top_array["Resources at"]).';
var archive_confirm_delete = '.json_encode(REPORT_ARCHIVE_CONFIRM_DELETE).';
var report_when = '.json_encode($probe_helper->report_when).';
var report_uploaded_by = '.json_encode(REPORTS_UPLOAD_BY).';

var galaxytool_language = '.json_encode($_SESSION['lang']).';
var galaxytool_techs = {
	vbt : '.$_SESSION['s_auth']->get_tech(iAuthorization::tech_vbt).',
	impulse : '.$_SESSION['s_auth']->get_tech(iAuthorization::tech_impulse).',
	hra : '.$_SESSION['s_auth']->get_tech(iAuthorization::tech_hra).',
	waffentech : '.$_SESSION['s_auth']->get_tech(iAuthorization::tech_weapon).',
	schildtech : '.$_SESSION['s_auth']->get_tech(iAuthorization::tech_shield).',
	rpz : '.$_SESSION['s_auth']->get_tech(iAuthorization::tech_rpz).'
};
var galaxytool_def_to_debris = '; echo ($def_to_debris) ? 'true' : 'false'; echo ';
var galaxytool_debris_rate = "'.$debris_rate.'";

var galaxytool_speedsim_text = '.json_encode(REPORTS_SPEEDSIM).';
var galaxytool_admin_safety_text = '.json_encode(ADMIN_SAFETY).';
var galaxytool_dragosim_text = '.json_encode(REPORTS_DRAGOSIM).';
var galaxytool_cargo_capacity_text = '.json_encode(REPORT_ARCHIVE_FLEET_CARGO).';
var galaxytool_phalanx_text = '.json_encode(DETAILEDINFO_PHALANX_AREA).';
var galaxytool_irak_text = '.json_encode(REPORT_ARCHIVE_IRAK_RANGE).';
var galaxytool_delete = '; echo ($_SESSION['s_auth']->get_permission(iAuthorization::permission_candelete)) ? 'true' : 'false'; echo ';
var galaxytool_report_archive_details = '.json_encode(REPORT_ARCHIVE_DETAILS).';
var galaxytool_report_archive_title = '.json_encode(REPORT_ARCHIVE_TITLE).';
var galaxytool_total_res_text = '.json_encode(REPORTS_ALL_RESOURCES).';
var galaxytool_autoheight = '.json_encode($_SESSION['s_auth']->get_setting(iAuthorization::setting_search_results)).';
var galaxytool_open_in_new_window_text = '.json_encode(GENERAL_OPEN_IN_NEW_WINDOW).';
';
?>
</script>
<?php
echo Layout::start_block(REPORTS_TITLE);
?>
<div id="ReportInline" style="min-width: 740px;"></div>
<?php
echo Layout::close_block();
?>
<script type="text/javascript" src="javascript/report_display.js"></script>
<script type="text/javascript"	src="javascript/report_fetch.js"></script>
<script type="text/javascript">
<?php
$moon = (isset($_GET['moon']) && $_GET['moon'] == "true") ? "true" : "false";
if (isset($_GET['coordinates']) && preg_replace("/\d+\:\d+\:\d+/","",$_GET['coordinates']) == "") {
$coordinates = $_GET['coordinates'];
?>
dojo.ready(function(){
	galaxytool.report_display.report_inline = true; // to hide link to new window
	show_report('<?php echo $coordinates; ?>',<?php echo $moon; ?>,true);
});
<?php
}
?>
</script>
<?php
echo Layout::make_footer($global_universe,$messages);
?>